import { TOKEN_KEY } from '@/constants'
import Cookies from 'js-cookie'
import { defineStore } from 'pinia'
import { ref } from 'vue'
//全局状态管理
export const useUserStore = defineStore('hm-user', () => {
  const token = ref(Cookies.get(TOKEN_KEY)||'')
  const setToken =(val:string)=>{
    token.value = val
    Cookies.set(TOKEN_KEY,val)
  }
  const removeToken=()=>{
    token.value = ''
    Cookies.remove(TOKEN_KEY)

  }
  return {
    token,
    setToken,
    removeToken
  }
})
